package com.fzy.Dao;

import com.fzy.beansa.Employee;

import java.util.ArrayList;
import java.util.List;

public class EmployeeDaoImpl extends BaseDao implements EmployeeDao {


    public List<Employee> SelectAllEmployee() {
        List<Employee> employeelist = new ArrayList<>();
        try {
            BaseDao basedao = new BaseDao();
            String sql = "select * from employee";
            employeelist = basedao.getList(Employee.class, sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return employeelist;
    }

    public Employee SelectEmployee(String employeeid) {
        Employee employee = new Employee();
        try {
            BaseDao basedao = new BaseDao();
            String sql = "select * from employee where employeeid=?";
            employee = basedao.getBean(Employee.class, sql, employeeid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return employee;
    }

    public int DeleteEmployee(String employeeid) {
        int rs = 0;
        try {
            BaseDao basedao = new BaseDao();
            String sql = "delete from employee where employeeid=?";
            rs = basedao.update(sql, employeeid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rs;
    }

    public int InsertEmployee(Employee employee) {
        int rs = 0;
        try {
            BaseDao basedao = new BaseDao();
            String sql = "insert into employee values(?,?,?)";
            rs = basedao.update(sql, employee.getEmployeeid(), employee.getEmployeename(), employee.getEmployeesalary());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rs;
    }

    public int UpdateEmployee(Employee employee) {
        int rs = 0;
        try {
            BaseDao basedao = new BaseDao();
            String sql = "update employee set employeename=?,employeesalary=? where employeeid=?";
            rs = basedao.update(sql, employee.getEmployeename(), employee.getEmployeesalary(), employee.getEmployeeid());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rs;
    }
}
